package utwente.hmi.touchmol.elements;

import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.JPanel;

/**
 * This class is used to make visual changes to the interface elements of TouchMol 
 * to reflect a change in turns. Any functional changes in the system should be made
 * in GUI classes.
 * @author Jeroen Logtenberg
 *
 */
public abstract class ButtonPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;

	/**
	 * Use this method to visualize a turn request, for instance to enter a queue.
	 * @param user The user that requests the turn.
	 */
	public abstract void requestTurn(UserButton user);
	
	/**
	 * Use this method to visualize the taking or assigning of a turn.
	 * @param user The user that takes the turn.
	 */
	public abstract void takeTurn(UserButton user);
	
	/**
	 * Use this method to visualize the release or loss of a turn.
	 * @param user The user that releases the turn.
	 */
	public abstract void releaseTurn(UserButton user);
	
	/**
	 * This method checks if the button panel is touched at a certain location.
	 * @param location The point on the screen where the touch has occurred.
	 * @return If the touch has occurred inside the panel.
	 */
	public boolean panelTouched(Point location){
		Rectangle r = this.getBounds();
		Point p = this.getLocationOnScreen();
		r.setLocation(p);
		return r.contains(location);
	}
	
	/**
	 * This method checks if and which button is touched at a certain location.
	 * @param location The point on the screen where touch has occurred
	 * @return The user ID of the button at the specified location, otherwise -1.
	 */
	public abstract UserButton buttonTouched(Point location);

}
